﻿myApp.controller("eventsController", function ($scope, $http, $modal, modalService, $sce, ngTableParams, $filter) {
    function pageInit() {
        document.title = "Penang Realty 世界地產 EVENTS";
        $scope.$emit('newPageLoaded', { 'title': 'Penang Realty 世界地產 EVENTS', 'description': 'Join our event to obtain first hand info.' });
        $scope.loader = { loading: true };
        var url = 'api/Events/GetEvents';
        $http.get(url).success(function (data) {
            $scope.data.Events = data;

            $scope.tableParams = new ngTableParams({
                page: 1,            // show first page
                count: 5,           // count per page
                filter: {
                    Name: ''       // initial filter
                }

            }, {
                total: $scope.data.Events.length, // length of data
                getData: function ($defer, params) {

                    var orderedEvents = params.filter() ? $filter('filter')($scope.data.Events, params.filter()) : $scope.data.Events;
                    // use build-in angular filter
                    orderedEvents = params.sorting() ?  $filter('orderBy')(orderedEvents, params.orderBy()) : orderedEvents;
                    params.total(orderedEvents.length); // set total for recalc pagination
                    $defer.resolve(orderedEvents.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                    $scope.loader = { loading: false };
                }
            })


        })

    }
    pageInit();



})